<template>
  <div class="app-container1 show-back-class">
    <div style="width: 100%;height: 60px;border-bottom: #1C97FF 1px solid;padding:  10px 20px;display: flex;">
      <img style="width: 340px; height: 40px; margin-right: 20px;" src="@/assets/bigScreen/index/LOGO.jpg" alt="">
      <big-tab-Bar />
    </div>
    <div class="content-bottom">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="产品分类" >
          <el-cascader style="width: 800px"
                       v-model="categorizeArr"
                       :options="$store.state.factorDict.productCategorizeDict0"
                       :props="{value:'code',label:'chineseName' ,checkStrictly: true }"
                       clearable></el-cascader>
        </el-form-item>
        <el-form-item label="产品名称" prop="name">
          <el-input v-model="queryParams.name" placeholder="请输入产品名称" clearable
            size="small"  @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
            <el-option class="index-option" v-for="dict in $store.state.factorDict.statusOptions"
                       :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['factor:productInfo:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['factor:productInfo:remove']"
          >删除</el-button>
        </el-col>
	    <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
      </el-row>

      <el-table v-loading="loading" :data="productInfoList" :height="tableHeight" @selection-change="handleSelectionChange" border>
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" align="center" type="index" width="50" />

        <el-table-column label="门类" align="center" prop="level0">
          <template slot-scope="scope">
            {{selectDictLabel($store.state.factorDict.productCategorizeDict0, scope.row.level0,'code','chineseName')}}
          </template>
        </el-table-column>
        <el-table-column label="大类" align="center" prop="level1">
          <template slot-scope="scope">
            {{selectDictLabel($store.state.factorDict.productCategorizeDict1, scope.row.level1,'code','chineseName')}}
          </template>
        </el-table-column>
        <el-table-column label="中类" align="center" prop="level2">
          <template slot-scope="scope">
            {{selectDictLabel($store.state.factorDict.productCategorizeDict2, scope.row.level2,'code','chineseName')}}
          </template>
        </el-table-column>
        <el-table-column label="小类" align="center" prop="level3">
          <template slot-scope="scope">
            {{selectDictLabel($store.state.factorDict.productCategorizeDict3, scope.row.level3,'code','chineseName')}}
          </template>
        </el-table-column>
        <el-table-column label="产品名称" align="center" prop="name" />
        <el-table-column label="排序" align="center" prop="orderNum" width="100"/>
        <el-table-column label="状态" align="center" prop="status" width="80">
          <template slot-scope="scope">
            {{selectDictLabelDefault($store.state.factorDict.statusOptions, scope.row.status)}}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                       v-hasPermi="['factor:productInfo:edit']" >修改</el-button>

            <el-button size="mini" type="text" icon="el-icon-setting" @click="handleConsumables(scope.row)">产品周期</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize" @pagination="getList" />

      <add-product-form ref="addProductFormRef"  @getList="getList"/>

      <product-stage-form ref="productStageFormRef"/>
    </div>
  </div>
</template>

<script>
import { listProductInfo, getProductInfo, delProductInfo, addProductInfo, updateProductInfo, exportProductInfo } from "@/api/factor/productInfo";
import AddProductForm from "./children/addProductForm"
import ProductStageForm from "./children/ProductStageForm"
import bigTabBar from '@/views/components/bigTabBar/index'
export default {
  name: "ProductInfo",
  components:{
    AddProductForm,ProductStageForm,bigTabBar
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品表格数据
      productInfoList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        level0: null,
        level1: null,
        level2: null,
        level3: null,
        name: null,
        status: null,
        orderNum: null,
      },
      categorizeArr:[],
      tableHeight: ''
    };
  },
  created() {
    this.tableHeight = window.innerHeight - 300;
    this.getList();
  },
  methods: {
    /** 查询产品列表 */
    getList() {
      this.loading = true;
      if(this.categorizeArr.length>0){
        this.queryParams.level0 = this.categorizeArr[0]
      }else {
        this.queryParams.level0 = null;
      }
      if(this.categorizeArr.length>1){
        this.queryParams.level1 = this.categorizeArr[1]
      }else {
        this.queryParams.level1 = null;
      }
      if(this.categorizeArr.length>2){
        this.queryParams.level2 = this.categorizeArr[2]
      }else {
        this.queryParams.level2 = null;
      }
      if(this.categorizeArr.length>3){
        this.queryParams.level3 = this.categorizeArr[3]
      }else {
        this.queryParams.level3 = null;
      }
      listProductInfo(this.queryParams).then(response => {
        this.productInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.categorizeArr=[];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length!==1;
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.addProductFormRef.handleAdd();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.addProductFormRef.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delProductInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },

    handleConsumables(row){
      this.$refs.productStageFormRef.handleShow(row);
    },
  }
};
</script>
<style lang="scss" scoped>
.app-container1{
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #000D17;
  // background: url("../../assets/bg2.jpg") no-repeat;
  // background-size: 100% 100%;
}
.content-bottom{
  width: 100%;
  height: calc(100% - 60px);
  background-color: #000D17;
  padding: 20px;
}
.pagination-container {
  height: 50px;
}
</style>